package org.example.myleet.p1137;

public class Solution {
    public int tribonacci(int n) {
        int t_n_3 = 0;
        int t_n_2 = 1;
        int t_n_1 = 1;
        if (n == 0) {
            return t_n_3;
        }
        if (n == 1) {
            return t_n_2;
        }
        if (n == 2) {
            return t_n_1;
        }
        int t_n = 0;
        for (int i = 3; i <= n; ++i) {
            t_n = t_n_1 + t_n_2 + t_n_3;
            t_n_3 = t_n_2;
            t_n_2 = t_n_1;
            t_n_1 = t_n;
        }
        return t_n;
    }
}
